import { $cToast } from '../../../utils/index'
Page({
  data: {},
  onLoad() { },
  showToast() {
    $cToast().show({
      type: 'success',
      duration: 1500,
      color: '#fff',
      text: '已完成',
      success: () => console.log('已完成')
    })

    // The same as above
    // $cToast().success('已完成', {
    //     duration: 1500,
    //     color: '#fff',
    //     success: () => console.log('已完成')
    // })
  },
  showToastCancel() {
    $cToast().show({
      type: 'cancel',
      duration: 1500,
      color: '#fff',
      text: '取消操作',
      success: () => console.log('取消操作')
    })

    // The same as above
    // $cToast().error('取消操作', {
    //     duration: 1500,
    //     color: '#fff',
    //     success: () => console.log('取消操作')
    // })
  },
  showToastErr() {
    $cToast().show({
      type: 'forbidden',
      duration: 1500,
      color: '#fff',
      text: '禁止操作',
      success: () => console.log('禁止操作')
    })

    // The same as above
    // $cToast().warning('禁止操作', {
    //     duration: 1500,
    //     color: '#fff',
    //     success: () => console.log('禁止操作')
    // })
  },
  showToastText() {
    $cToast().show({
      type: 'text',
      duration: 1500,
      color: '#fff',
      text: '文本提示',
      success: () => console.log('文本提示')
    })

    // The same as above
    // $cToast().info('文本提示', {
    //     duration: 1500,
    //     color: '#fff',
    //     success: () => console.log('文本提示')
    // })
  },
  showToastIcon() {
    $cToast().show({
      type: 'default',
      duration: 1500,
      color: '#fff',
      icon: 'ios-happy',
      text: '自定义图标',
      success: () => console.log('自定义图标')
    })
  },
  showToastReturn() {
    if (this.timeout) clearTimeout(this.timeout)

    const hide = $cToast().show({
      type: 'success',
      duration: 1500,
      color: '#fff',
      text: '已完成',
    })

    this.timeout = setTimeout(hide, 1000)
  },
  showToastPromie() {
    const hide = $cToast().show({
      type: 'success',
      duration: 1500,
      color: '#fff',
      text: '已完成',
    })

    // hide.promise.then(() => console.log('success'))
    hide.then(() => console.log('success'))
  },
})